#include <geo\inverseMercatorProjection.h>

inverseMercatorProjection::inverseMercatorProjection() {

};

inverseMercatorProjection::~inverseMercatorProjection() {

};

geoLocation
inverseMercatorProjection::getGEO(vec2d tileLocation2d, int level) {
  
  double longitude = (tileLocation2d.x / pow(2.0, level)) * 360.0 - 180.0;

  double n = PI - 2.0 * PI * tileLocation2d.y / pow(2.0, level);
	double latitude = 180.0 / PI * atan(0.5 * (exp(n) - exp(-n)));
  
  return geoLocation(latitude, longitude);
};

geoLocation
inverseMercatorProjection::getGEO(vec2i tileLocation2i, int level) {
  
  double longitude = (tileLocation2i.x / pow(2.0, level)) * 360.0 - 180.0;

  double n = PI - 2.0 * PI * tileLocation2i.y / pow(2.0, level);
	double latitude = 180.0 / PI * atan(0.5 * (exp(n) - exp(-n)));
  
  return geoLocation(latitude, longitude);
};